﻿using System.Collections.Generic;
using System.Linq;
using Citi.GenericApplications.SchedulerUi.EmailSenderWcf;

namespace Citi.PTSConsolidation.SchedulerUI.Util
{
    public class EmailSenderHelper
    {
        public static void SendEmailWithTemplate(List<string> to, List<string> cc, List<string> bcc, int templateId, Dictionary<string, string> parameters)
        {
            using (var client = new Citi.PTSConsolidation.SchedulerUI.EmailSenderWcf.EmailClient())
            {
                to = to != null ? to.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList() : new List<string>();
                cc = cc != null ? cc.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList() : new List<string>();
                bcc = bcc != null ? bcc.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList() : new List<string>();

                var email = new Email
                {
                    TemplateId = templateId,
                    Importance = EnumsEmailImportance.Normal,
                    To = to.Select(x => new EmailAddress { Description = x }).ToList(),
                    Cc = cc.Select(x => new EmailAddress { Description = x }).ToList(),
                    Bcc = bcc.Select(x => new EmailAddress { Description = x }).ToList(),
                    Parameters = parameters
                };

                client.InsertEmailInQueue(email);
            }
        }
    }
}